package com.project.webpage.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.project.webpage.dto.BaseParam;
import com.project.webpage.dto.GjxlDto;
import com.project.webpage.dto.GjxlParam;
import com.project.webpage.dto.GjxlRuleDto;
import com.project.webpage.entity.*;
import com.project.webpage.mapper.GjxlMapper;
import com.project.webpage.service.GjxlService;
import com.project.webpage.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class GjxlServiceImpl implements GjxlService {

    @Resource
    private GjxlMapper gjxlMapper;
    @Resource
    UserService userService;

    @Override
    @DS("master")
    public List<Gjxl> getList(String uid) {
        List<Gjxl> list = new ArrayList<>();
        List<UserXl> userXlList = userService.getXlList(uid);
        if (userXlList.size() > 0) {
            Example example = new Example(Gjxl.class);
            Example.Criteria c = example.createCriteria();
            List<Integer> idList = userXlList.stream().map(UserXl::getJgxlid).collect(Collectors.toList());
            c.andIn("jgxlid", idList);
            list = gjxlMapper.selectByExample(example);
        }
        return list;
    }

    @Override
    @DS("master")
    public List<GjxlDto> getListForPage(GjxlParam param) {
        return gjxlMapper.selectListByUid(param);
    }

    @Override
    @DS("master")
    public List<GjxlDto> getXlbmYuJingListForPage(GjxlParam param) {
        return gjxlMapper.selectXlbmYuJingListByUid(param);
    }

    @Override
    @DS("master")
    public List<GjxlDto> getNotCorrectXlmcListForPage(BaseParam param) {
        return gjxlMapper.selectNotCorrectXlmcListByUid(param);
    }

    @Override
    @DS("master")
    public List<QzcySmzmc> getCySmzmcListForPage(BaseParam param) {
        return gjxlMapper.selectCySmzmcListByUid(param);
    }

    @Override
    @DS("master")
    public List<QzcyZj> getCyZjListForPage(BaseParam param) {
        return gjxlMapper.selectCyZjListByUid(param);
    }

    @Override
    @DS("master")
    public List<QzcyPc> getCyPcListForPage(BaseParam param) {
        return gjxlMapper.selectCyPcListByUid(param);
    }

    @Override
    @DS("master")
    public List<QzcyBc> getCyBcListForPage(BaseParam param) {
        return gjxlMapper.selectCyBcListByUid(param);
    }

    @Override
    @DS("master")
    public List<GjxlRuleDto> getRuleListForPage(GjxlParam param) {
        return gjxlMapper.selectRuleListByUid(param);
    }

    @Override
    @DS("master")
    public List<GjxlRuleDto> getRule(GjxlRuleDto param) {
        return gjxlMapper.selectRule(param);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void updateRuleId(GjxlRuleDto param) {
        gjxlMapper.updateRuleId(param);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void updateXlbm(GjxlRuleDto param) {
        gjxlMapper.updateXlbm(param);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void insertNoweekend(GjxlRuleDto param) {
        gjxlMapper.insertNoweekend(param);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void deleteNoweekend(GjxlRuleDto param) {
        gjxlMapper.deleteNoweekend(param);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void insertSingle(GjxlRuleDto param) {
        gjxlMapper.insertSingle(param);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void deleteSingle(GjxlRuleDto param) {
        gjxlMapper.deleteSingle(param);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void insertGp(GjxlRuleDto param) {
        gjxlMapper.insertGp(param);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void deleteGp(GjxlRuleDto param) {
        gjxlMapper.deleteGp(param);
    }

    @Override
    @DS("master")
    public GjxlRuleDto getDjg(GjxlParam param) {
        return gjxlMapper.selectDjg(param);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void insertDjg(GjxlRuleDto param) {
        gjxlMapper.insertDjg(param);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void updateDjg(GjxlRuleDto param) {
        gjxlMapper.updateDjg(param);
    }
}
